﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DavidDB.ADO;
namespace MaterialStorage
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Tools.Screen screen = new Tools.Screen();
            this.Width = screen.Width / 2;
            this.Height = screen.Height / 2;
            //  this.po = FormStartPosition.CenterParent;
            this.Title = "物料管理";
            this.statusValue.Text = "哈哈";
            this.barLine1.X2 = this.Width;
            this.barLine2.X2 = this.Width;
            //  ContextMenu statusmenu=new ContextMenu();
            //   statusmenu.v

            //   this.FormBorderStyle = FormBorderStyle.None;
            //   this.menuStrip1.BackColor = Color.Red;
        }



        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        private void About_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Prowed by David");
        }
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            var query = GetListByPageAndKeys();
            MessageBox.Show(query.Count.ToString());
        }



        /// <summary>
        /// ok
        /// </summary>
        /// <returns></returns>
        private List<dynamic> GetListByPageAndKeys()
        {
            DavidDB.ADO.DBManager db = new DBManager();
            Model.QuantityRecoder recoder = new Model.QuantityRecoder();
            recoder.Desp = "%aa%";
            int pagecount = 0;
            int recodeCount = 0;
            var query = db.GetListByPageAndKeys(1, 1, recoder, out pagecount, out recodeCount);
            db.Commit();
            db.Dispose();
            return query;
        }

        /// <summary>
        /// ok
        /// </summary>
        /// <returns></returns>
        private List<dynamic> GetListByPageLikeKey()
        {
            DavidDB.ADO.DBManager db = new DBManager();
            Model.QuantityRecoder recoder = new Model.QuantityRecoder();
            recoder.Desp = "%aa%";
            int pagecount = 0;
            int recodeCount = 0;
            var query = db.GetListByPageLikeKey(1, 1, recoder, out pagecount, out recodeCount);
            db.Commit();
            db.Dispose();
            return query;
        }

        /// <summary>
        /// ok
        /// </summary>
        /// <returns></returns>
        private List<dynamic> GetListByPage()
        {
            DavidDB.ADO.DBManager db = new DBManager();
            Model.QuantityRecoder recoder = new Model.QuantityRecoder();
            int pagecount = 0;
            int recodeCount = 0;
            var query = db.GetListByPage(1, 1, out pagecount, out recodeCount, recoder);
            db.Commit();
            db.Dispose();
            return query;
        }
        /// <summary>
        /// ok
        /// </summary>
        /// <returns></returns>
        private List<dynamic> GetList()
        {
            DavidDB.ADO.DBManager db = new DBManager();

            Model.QuantityRecoder recoder = new Model.QuantityRecoder();
            var query = db.GetList(recoder);

            db.Commit();
            db.Dispose();
            return query;
        }

        /// <summary>
        /// ok
        /// </summary>
        /// <returns></returns>
        private void Edit()
        {
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            Model.QuantityRecoder model = GetModel();
            model.Pdate = DateTime.Now;
            model.Direction = 3;
            model.Desp = "aaa";
            db.Edit(model);
            db.Commit();
            db.Dispose();
        }
        /// <summary>
        /// ok
        /// </summary>
        /// <returns></returns>
        private Model.QuantityRecoder GetModel()
        {
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();

            Model.QuantityRecoder model = new Model.QuantityRecoder();
            model.Id = 1;
            model = db.GetModel(model);
            model.Include("Material", db);
            db.Commit();
            db.Dispose();
            return model;
        }
        /// <summary>
        /// ok
        /// </summary>
        /// <returns></returns>
        private void Insert()
        {
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            //Model.Users user = new Model.Users();

            Model.QuantityRecoder recoder = new Model.QuantityRecoder();
            recoder.Desp = "相关描述";
            recoder.Direction = 1;
            recoder.MaterialId = 2;
            recoder.Pdate = DateTime.Now;
            recoder.PickerId = 1;
            recoder.Quantity = 20.2f;
            recoder.SurplusQuantity = 9;


            db.Insert(recoder);

            db.Commit();
            db.Dispose();
        }
    }
}
